(function(){
    var imDefConfig = {
        version : '1.0.0.32',   //${im_version}
        path : ujsConfig.path + 'app/im/',
        emojiResPath : ujsConfig.path + 'app/im/res/emoji',
        debug : true    //${im_debug}
    };    
    imConfig = $.extend({}, imDefConfig, window.imConfig);
    
    var resConfig = {};
    //load css
    if(imConfig['debug']){
        ujs.writeScript(ujsConfig.path + 'grunt/resource_path/app/im/css_res.js', '', imConfig['version'] );
        ujs.writeScriptText([
            'var allCSSes = ujs.getResPath(' + JSON.stringify(resConfig) + ');',
            'var cssesImport = [];',
            'for(var i=0; i<allCSSes.length; i++){',
                'cssesImport.push( "@import url(' + ujsConfig['rootPath'] + imConfig['path'] + 'css/" + allCSSes[i] + ");" );',
            '};',
            'ujs.writeCSSText(cssesImport.join("\\r\\n"));'
        ].join('\r\n'));
    } else {
        ujs.writeCSS('build/app/im/im.min.css', ujsConfig.path, imConfig['version']);
    }    
    //load javascript
    if(imConfig['debug']){
        ujs.writeScript(ujsConfig.path + 'grunt/resource_path/app/im/js_res.js', '', imConfig['version'] );
        ujs.writeScriptText("ujs.writeScript(ujs.getResPath(" + JSON.stringify(resConfig) + "), '" + imConfig['path'] + "js/', ujs.version);");                
    } else {
        ujs.writeScript('build/app/im/im.min.js', ujsConfig.path, imConfig['version'] );
    }
})();